﻿using System;
using Microsoft.ComplexEventProcessing;
using Microsoft.ComplexEventProcessing.Adapters;

namespace $Namespace$
{


    public sealed class $FactoryClassName$ : IInputAdapterFactory<$ConfigClassName$>
                                                //  ,IDeclareAdvanceTimeProperties<$ConfigClassName$>
    {

        public InputAdapterBase Create($ConfigClassName$ configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            //TODO: Determine if you need anything more sophisticated in the Create.
            //This may include logic to reuse already created adapters.
            InputAdapterBase adapter = default(InputAdapterBase);

            switch (eventShape)
            {
                case EventShape.Edge:
                    adapter = new $EdgeClassName$(configInfo, cepEventType);
                    break; 
                case EventShape.Interval:
                    adapter = new $IntervalClassName$(configInfo, cepEventType);
                    break;
                case EventShape.Point:
                    adapter = new $PointClassName$(configInfo, cepEventType);
                    break; 
                default:                    
                    throw new ArgumentException(string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "$FactoryClassName$ cannot instantiate adapter with event shape {0}",
                        eventShape.ToString()));         }
            return adapter;
        }

        /// <summary>
        /// Dispose method.
        /// </summary>
        public void Dispose()
        {
        }

        /**
         * Uncomment this section when implementing IDeclareAdvanceTimeSettings.
        /// <summary>
        /// Specifies the CTI behavior of this adapter. This method will be called whenever
        /// a new adapter instance is needed, with the respective configuration and event type.
        /// </summary>
        /// <typeparam name="TPayload">Type of the payload.</typeparam>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <returns>An instance of AdapterAdvanceTimeSettings.</returns>
        [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "By Design")]
        public AdapterAdvanceTimeSettings DeclareAdvanceTimeProperties<TPayload>($ConfigClassName$ configInfo, EventShape eventShape)
        {
            //This will inject a CTI 1 tick after every event and drops any late-arriving packets.
            return new AdapterAdvanceTimeSettings(
                new AdvanceTimeGenerationSettings(1, TimeSpan.FromTicks(-1)),
                AdvanceTimePolicy.Drop);
        }
        **/
    }
}
